package com.controller;


import com.result.Result;
import com.service.FileUploadService;
import com.vo.ApkUplaodResultVo;
import com.vo.FileUploadResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * author chihaojie
 * 时间  2018年10月1日00:15:06
 */
@Api(value = "upload")
@CrossOrigin
@RestController
public class UploadController {

	@Autowired
	private FileUploadService fileUploadService;

	@ApiOperation(value = "上传图片", httpMethod = "POST", notes = "上传图片")
	@ResponseBody
	@RequestMapping(value = "/uploadImg",method=RequestMethod.POST)
	public Result<FileUploadResultVo> uploadBookImg(HttpServletRequest request, HttpServletResponse response, @RequestParam("img") MultipartFile multipartfile) {
     return fileUploadService.uploadBookImg(request,response,multipartfile);
	}





	/**
	 * 上传视频文件
	 *
	 */
	@ApiOperation(value = "上传视频", httpMethod = "POST", notes = "上传视频")
	@ResponseBody
	@RequestMapping(value = "/uploadVideo",method=RequestMethod.POST)
	public Result<FileUploadResultVo> uploadVideo(HttpServletRequest request, HttpServletResponse response, @RequestParam("video") MultipartFile video) {
		return fileUploadService.uploadVideo(request,response,video);
	}

	/**
	 * 上传apk文件
	 *
	 */
	@ApiOperation(value = "上传apk", httpMethod = "POST", notes = "上传apk")
	@ResponseBody
	@RequestMapping(value = "/uploadApk",method=RequestMethod.POST)
	public Result<ApkUplaodResultVo> uploadApk(HttpServletRequest request, HttpServletResponse response, @RequestParam("apk") MultipartFile apk) {
		return fileUploadService.uploadApk(request,response,apk);
	}


	/**
	 * 根据url从远程服务器下载文件
	 */
	@ApiOperation(value = "下载图片", httpMethod = "GET", notes = "下载图片")
	@RequestMapping(value = "/downloadImg",method=RequestMethod.GET)
	public Result<String> downloadImg(HttpServletRequest request, HttpServletResponse response) {
		return fileUploadService.downloadImg(request,response);
	}
}
